package com.example.lastwork.service;


import com.example.lastwork.common.service.LogicService;
import com.example.lastwork.dao.ItemDao;
import com.example.lastwork.dao.ShopDao;
import com.example.lastwork.dao.ShopItemDao;
import com.example.lastwork.entity.Item;
import com.example.lastwork.entity.Orders;
import com.example.lastwork.entity.Shop;
import com.example.lastwork.entity.ShopItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ShopService extends LogicService<ShopDao, Shop, Long> {
    @Resource
    private ItemDao itemDao;

    @Resource
    private ShopItemDao shopItemDao;

    public ShopService(@Autowired ShopDao dao){
        super(dao);
    }

    public ShopItem onSale(Long shopItemId){
        ShopItem shopItem = shopItemDao.getReferenceById(shopItemId);
        shopItem.setState(true);
        shopItemDao.save(shopItem);
        return shopItem;
    }

    public ShopItem downSale(Long shopItemId){
        ShopItem shopItem = shopItemDao.getReferenceById(shopItemId);
        shopItem.setState(false);
        shopItemDao.save(shopItem);
        return shopItem;
    }

    public List<Orders> getOrdersList(Long shopId){
        return getDAO().getOrdersList(shopId);
    }

    public List<Shop> getAllShop(){
        return getDAO().getAllShop();
    }

    public List<Shop> getMyShop(Long businessId){
        return getDAO().getMyShop(businessId);
    }
}
